#include "Combo.h"

Combo::Combo() {
    this->currentTouchRequired = 0;
    this->currentTimeToReset = CONF_COMBO_TIME_TO_RESET;
}

bool Combo::init() {
    this->currentCombo = CONF_COMBO_MIN;
    this->countDownSpeed = -1;
    this->raise(0);
    return true;
}

Combo::~Combo() {
}

void Combo::update(float dt) {
    float descreaseCombo = this->countDownSpeed * dt;
    this->raise(-descreaseCombo);
    
    if (this->currentCombo == CONF_COMBO_MIN && this->currentTouchRequired == CONF_COMBO_TOUCH_REQUIRED) {
        this->currentTimeToReset -= dt;
        if (this->currentTimeToReset < 0) {
            this->currentTouchRequired = 0;
            this->currentTimeToReset = CONF_COMBO_TIME_TO_RESET;
        }
    }
}

void Combo::raise(float combo) {
    if (combo > 0 && this->currentTouchRequired < CONF_COMBO_TOUCH_REQUIRED) {
        this->currentTouchRequired++;
        return;
    }
    this->currentCombo += combo;
    if (this->currentCombo < CONF_COMBO_MIN) {
        this->currentCombo = CONF_COMBO_MIN;
    } else if (this->currentCombo > CONF_COMBO_MAX) {
        this->currentCombo = CONF_COMBO_MAX;
    }
    
    int comboInt = ceil(this->currentCombo);
    if (comboInt == 2) {
        this->countDownSpeed = 0.4f;
    } else if (comboInt == 3) {
        this->countDownSpeed = 0.6f;
    } else if (comboInt == 4) {
        this->countDownSpeed = 1.6f;
    } else if (comboInt == 5) {
        this->countDownSpeed = 3.2f;
    } else {
        this->countDownSpeed = 0.2f;
    }
}

int Combo::getCurrentComboInt() {
    int currentComboInt = ceil(this->currentCombo);
    if (currentComboInt < 1) {
        currentComboInt = 1;
    }
    return currentComboInt;
}